package com.hongawen.jvm.loadclass;

import com.sun.javafx.binding.StringFormatter;
import sun.misc.Launcher;

import java.net.URL;
import java.util.Arrays;

/**
 * @author hongawen
 * @version 1.0.0
 * @date 2021年06月18日 10:39
 */
public class TestJdkClassLoader {

    public static void main(String[] args) {
        System.out.println(String.class.getClassLoader());
        System.out.println(com.sun.crypto.provider.DESKeyFactory.class.getClassLoader());
        System.out.println(TestJdkClassLoader.class.getClassLoader());
        System.out.println("==================================");
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        ClassLoader extClassLoader = systemClassLoader.getParent();
        ClassLoader bootstrapClassLoader = extClassLoader.getParent();
        System.out.println("systemClassLoader:" + systemClassLoader);
        System.out.println(StringFormatter.format("{}:{}", "extClassLoader", extClassLoader));
        System.out.println(StringFormatter.format("{}:{}", "bootstrapClassLoader", bootstrapClassLoader));
        System.out.println("======================================");
        System.out.println("bootstrapLoader加载以下文件：");
        URL[] urls = Launcher.getBootstrapClassPath().getURLs();
        Arrays.asList(urls).forEach(
                System.out::println
        );
        System.out.println("extClassloader加载以下文件：");
        System.out.println(System.getProperty("java.ext.dirs"));
        System.out.println();
        System.out.println();
        System.out.println("appClassLoader加载以下文件：");
        System.out.println(System.getProperty("java.class.path"));
    }

}
